package edu.hawaii.myisern.action;

import edu.hawaii.myisern.model.IsernManager;
import net.sourceforge.stripes.action.FileBean;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;

/**
 * Handles the importing of XML files.
 * 
 * @author Shaoxuan Zhang
 *
 */
public class XmlActionBean extends IsernActionBean {
  private FileBean importXmlFile;

  /**
   * Gets the import XML file.
   * 
   * @return  The import XML file.
   */
  public FileBean getImportXmlFile() {
      return importXmlFile;
  }

  /**
   * Sets the import XML file.
   * 
   * @param file  The import XML file.
   */
  public void setImportXmlFile(FileBean file) {
      this.importXmlFile = file;
  }
  
  /**
   * Forwards the user to the appropriate page.
   * 
   * @return  The JSP page to display.
   */
  public Resolution importXml() {
    IsernManager im = new IsernManager();
    switch (im.importXml(importXmlFile)) {
      case 1:
        return new ForwardResolution("/collaborations.jsp");
      case 2:
        return new ForwardResolution("/researchers.jsp");
      default:
        return new ForwardResolution("/organizations.jsp");
    }
  }
  
}
